package light.mvc.model.admin;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import light.mvc.model.base.IdEntity;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

@Entity
@Table(name = "resource")
@DynamicInsert(true)
@DynamicUpdate(true)
public class Tresource extends IdEntity implements java.io.Serializable {
	private static final long serialVersionUID = 1L;
	
	private String name;
	private String url;
	private String description;
	
	private Integer resourceType;
	
	
	private String iconStr;
	
	private Tresource resource;	//父级资源
	private Set<Tresource> resources = new HashSet<Tresource>(0);	//子级资源
	private Set<Trole> roles = new HashSet<Trole>(0);	//
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id")
	public Tresource getResource() {
		return resource;
	}
	public void setResource(Tresource resource) {
		this.resource = resource;
	}
	
	@OneToMany(mappedBy="resource")
	public Set<Tresource> getResources() {
		return resources;
	}
	public void setResources(Set<Tresource> resources) {
		this.resources = resources;
	}
	
	@ManyToMany()
	@JoinTable(name = "role_resource",
	joinColumns = {@JoinColumn(name="resource_id",nullable=false,updatable=false)},
	inverseJoinColumns = {@JoinColumn(name="role_id",nullable=false,updatable=false)}
	)
	public Set<Trole> getRoles() {
		return roles;
	}
	public void setRoles(Set<Trole> roles) {
		this.roles = roles;
	}
	
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getIconStr() {
		return iconStr;
	}
	public void setIconStr(String iconStr) {
		this.iconStr = iconStr;
	}
	public Integer getResourceType() {
		return resourceType;
	}
	public void setResourceType(Integer resourceType) {
		this.resourceType = resourceType;
	}	
	
}